﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// Condition: Write a program that finds the maximal sequence of 
//            equal elements in an array.


class MaxSequence
{
    static void Main()
    {
        // 1. initialize array

        Console.Write("Enter number of element in integer array: ");
        int n = int.Parse(Console.ReadLine());
        int[] myArr = new int[n];
        Console.WriteLine("Enter elements of integer array: ");
        for (int index = 0; index < n; index++)
        {
            Console.Write("element[{0}]= ", index);
            myArr[index] = int.Parse(Console.ReadLine());
        }
        Console.WriteLine();

        // 2. helping variables

        int len = 1;
        int start = 0;
        int bestStart = 0;
        int bestLen = 1;
        int count = 0;

        // 3. Solution  

        for (int i = 1; i < myArr.Length; i++)
        {
            if (myArr[i] != myArr[i - 1])
            {
                len = 1;
                continue;
            }
            if (myArr[i] == myArr[i - 1])
            {
                len++;
                start = myArr[i];
            }
            if (bestLen == len && bestLen != 1)
            {
                count++;
            }
            if (bestLen < len)
            {
                bestLen = len;
                bestStart = start;
                count = 0;
            }
        }

        // 4. Output the result 

        if (bestStart == 0)
        {
            Console.WriteLine("No sequence of repeated elements.");
        }
        else if (count != 0)
        {
            Console.WriteLine("There are more than one sequence with same length.");
        }
        else if (bestStart != 0)
        {
            Console.Write("The maximum sequence of repeated elements is: { ");
            for (int i = 0; i < bestLen; i++)
            {
                Console.Write("{0} ", bestStart);
            }
            Console.Write("}");
        }
        Console.WriteLine();

    }
}

